<?php

namespace app\home\model;

use app\common\model\Article as ArticleModel;

/**
 * 文章模型
 * Class Article
 * @package app\store\model
 */
class Article extends ArticleModel
{

    public function getCreateTimeAttr($value)
    {
        return date('d M Y',$value);
    }
    /**
     * 获取文章列表 
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getList($params,$field = '*')
    {
        $where = 'article_status = 1';
        isset($params['category_id']) && $where .= ' AND category_id = '.$params['category_id'];
        isset($params['search']) && $where .= ' AND article_title LIKE "%'.$params['search'].'%"';
        return $this->with(['image','category'])->where('is_delete', '=', 0)
            ->field($field)
            ->where($where)
            ->order(['article_sort' => 'asc', 'create_time' => 'desc'])
            ->paginate(15, false, [
                'query' => request()->request()
            ]);
    }

    /**
     * 获取文章总数量
     * @param array $where
     * @return int|string
     */
    public static function getArticleTotal($where = [])
    {
        $model = new static;
        !empty($where) && $model->where($where);
        return $model->where('is_delete', '=', 0)->count();
    }

}